/*     */ package com.zimbra.cs.service.formatter;
/*     */ 
/*     */ import com.zimbra.common.service.ServiceException;
/*     */ import com.zimbra.common.util.zip.ZipOutputStream;
/*     */ import com.zimbra.cs.service.UserServletContext;
/*     */ import com.zimbra.cs.service.UserServletException;
/*     */ import java.io.IOException;
/*     */ import java.io.InputStream;
/*     */ import java.io.OutputStream;
/*     */ import java.util.Map;
/*     */ import java.util.zip.ZipInputStream;
/*     */ import javax.servlet.http.HttpServletResponse;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class ZipFormatter
/*     */   extends ArchiveFormatter
/*     */ {
/*     */   public class ZipArchiveInputStream
/*     */     implements ArchiveFormatter.ArchiveInputStream
/*     */   {
/*     */     private ZipInputStream is;
/*     */     
/*     */     public class ZipArchiveInputEntry
/*     */       implements ArchiveFormatter.ArchiveInputEntry
/*     */     {
/*     */       private java.util.zip.ZipEntry entry;
/*     */       
/*  38 */       public ZipArchiveInputEntry(ZipInputStream is)
/*  38 */         throws IOException { this.entry = is.getNextEntry(); }
/*     */       
/*  40 */       public long getModTime() { return this.entry.getTime(); }
/*  41 */       public String getName() { return this.entry.getName(); }
/*  42 */       public long getSize() { return this.entry.getSize(); }
/*  43 */       public int getType() { return 0; }
/*     */       
/*  45 */       public boolean isUnread() { return (this.entry.getComment() != null) && (this.entry.getComment().endsWith("-unread")); }
/*     */     }
/*     */     
/*     */ 
/*     */ 
/*     */ 
/*     */     public ZipArchiveInputStream(InputStream is, String cset)
/*     */     {
/*  53 */       this.is = new ZipInputStream(is);
/*     */     }
/*     */     
/*  56 */     public void close() throws IOException { this.is.close(); }
/*  57 */     public InputStream getInputStream() { return this.is; }
/*     */     
/*  59 */     public ArchiveFormatter.ArchiveInputEntry getNextEntry() throws IOException { ZipArchiveInputEntry zaie = new ZipArchiveInputEntry(this.is);
/*     */       
/*  61 */       return zaie.entry == null ? null : zaie;
/*     */     }
/*     */     
/*  64 */     public int read(byte[] buf, int offset, int len) throws IOException { return this.is.read(buf, offset, len); }
/*     */   }
/*     */   
/*     */   public class ZipArchiveOutputStream implements ArchiveFormatter.ArchiveOutputStream {
/*     */     private ZipOutputStream os;
/*     */     
/*     */     public class ZipArchiveOutputEntry implements ArchiveFormatter.ArchiveOutputEntry {
/*     */       private com.zimbra.common.util.zip.ZipEntry entry;
/*     */       
/*     */       public ZipArchiveOutputEntry(String path, String name, int type, long date) {
/*  74 */         this.entry = new com.zimbra.common.util.zip.ZipEntry(path);
/*  75 */         this.entry.setComment(name);
/*  76 */         this.entry.setTime(date);
/*  77 */         this.entry.setUnixMode(432);
/*     */       }
/*     */       
/*  80 */       public void setUnread() { this.entry.setUnixMode(416);
/*  81 */         this.entry.setComment(this.entry.getComment() + "-unread"); }
/*     */       
/*  83 */       public void setSize(long size) { this.entry.setSize(size); }
/*     */     }
/*     */     
/*     */ 
/*     */     public ZipArchiveOutputStream(OutputStream os, String cset, int lvl)
/*     */       throws IOException
/*     */     {
/*  90 */       this.os = new ZipOutputStream(os);
/*  91 */       this.os.setEncoding(cset);
/*  92 */       if ((lvl >= 0) && (lvl <= 9))
/*  93 */         this.os.setLevel(lvl); }
/*     */     
/*  95 */     public void close() throws IOException { this.os.close(); }
/*  96 */     public void closeEntry() throws IOException { this.os.closeEntry(); }
/*  97 */     public OutputStream getOutputStream() { return this.os; }
/*  98 */     public int getRecordSize() { return 2048; }
/*     */     
/*     */     public ArchiveFormatter.ArchiveOutputEntry newOutputEntry(String path, String name, int type, long date) {
/* 101 */       return new ZipArchiveOutputEntry(path, name, type, date);
/*     */     }
/*     */     
/* 104 */     public void putNextEntry(ArchiveFormatter.ArchiveOutputEntry entry) throws IOException { this.os.putNextEntry(((ZipArchiveOutputEntry)entry).entry); }
/*     */     
/* 106 */     public void write(byte[] buf) throws IOException { this.os.write(buf); }
/*     */     
/* 108 */     public void write(byte[] buf, int offset, int len) throws IOException { this.os.write(buf, offset, len); }
/*     */   }
/*     */   
/*     */   public String[] getDefaultMimeTypes()
/*     */   {
/* 113 */     return new String[] { "application/zip", "application/x-zip-compressed" };
/*     */   }
/*     */   
/*     */   public FormatterFactory.FormatType getType()
/*     */   {
/* 118 */     return FormatterFactory.FormatType.ZIP;
/*     */   }
/*     */   
/* 121 */   protected boolean getDefaultMeta() { return false; }
/*     */   
/*     */   protected ArchiveFormatter.ArchiveInputStream getInputStream(UserServletContext context, String charset) throws IOException, ServiceException, UserServletException
/*     */   {
/* 125 */     return new ZipArchiveInputStream(context.getRequestInputStream(-1L), charset);
/*     */   }
/*     */   
/*     */   protected ArchiveFormatter.ArchiveOutputStream getOutputStream(UserServletContext context, String charset)
/*     */     throws IOException
/*     */   {
/* 131 */     OutputStream os = context.resp.getOutputStream();
/* 132 */     String zlv = (String)context.params.get("zlv");
/* 133 */     int lvl = -1;
/*     */     
/* 135 */     if ((zlv != null) && (zlv.length() > 0)) {
/*     */       try {
/* 137 */         lvl = Integer.parseInt(zlv);
/*     */       } catch (NumberFormatException x) {}
/*     */     }
/* 140 */     return new ZipArchiveOutputStream(os, charset, lvl);
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/service/formatter/ZipFormatter.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */